import cv2
import json

cap = cv2.VideoCapture("/dev/video20")
cap.set(3, 680)
cap.set(4, 480)

for _ in range(10):
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)
    dbg_img = frame.copy()

with open("cali.json", "r") as f:
    result = json.load(f)
    for i in result:
        if i["valid"]:
            cv2.circle(dbg_img, i["center"], 5, (0, 0, 255), -1)
            cv2.circle(
                dbg_img,
                (
                    int(i["center"][0] + i["offset"][0]),
                    int(i["center"][1] + i["offset"][1]),
                ),
                5,
                (0, 255, 255),
                -1,
            )
        else:
            cv2.circle(dbg_img, i["center"], 5, (255, 0, 0), -1)

cv2.imshow("dbg", dbg_img)
cv2.waitKey(0)
